//
//  EPMOriginalView.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/3/29.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMOriginalView.h"

@interface EPMOriginalView()
@property (weak,nonatomic) UIImageView* imgIcon;
@property (weak,nonatomic) UILabel* labName;
@property (weak,nonatomic) UIImageView* imgMemberShip;
@property (weak,nonatomic) UILabel* labSource;
@property (weak,nonatomic) UIImageView* imgVarif;
@property (weak,nonatomic) YYLabel* labContent;
@property (weak,nonatomic) EPMPhotoView* viewPhoto;
@property (weak,nonatomic) UILabel* labCreatTime;
@property (strong,nonatomic) MASConstraint* selfBottomConstraint;
@end
@implementation EPMOriginalView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]){
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    return self;
}
#pragma
#pragma-设置UI
- (void)setupUI{
    UIImageView* imgIcon = [[UIImageView alloc]init];
    _imgIcon = imgIcon;
    [self addSubview:imgIcon];
    UILabel* labName = [UILabel EPM_Title:nil textColor:[UIColor darkGrayColor] fontSize:FONTSIZENORMAL];
    _labName = labName;
    [self addSubview:labName];
    UIImageView* imgMemberShip = [UIImageView new];
    _imgMemberShip = imgMemberShip;
    [self addSubview:imgMemberShip];
    imgMemberShip.image = [UIImage imageNamed:@"common_icon_membership_expired"];
    UILabel* labSource = [UILabel EPM_Title:nil textColor:[UIColor darkGrayColor] fontSize:FONTSIZESMALL];
    _labSource = labSource;
    [self addSubview:labSource];
    labSource.text = @"来源";
    UIImageView* imgVerif = [UIImageView new];
    _imgVarif = imgVerif;
    [self addSubview:imgVerif];
    imgVerif.image = [UIImage imageNamed:@"avatar_grassroot"];
    
    UILabel* labCreatTime = [UILabel EPM_Title:nil textColor:[UIColor darkGrayColor] fontSize:FONTSIZESMALL];
    _labCreatTime = labCreatTime;
    [self addSubview:labCreatTime];
    labCreatTime.text = @"创建时间";
    
    YYLabel* labContent = [YYLabel new];
    labContent.font = [UIFont systemFontOfSize:FONTSIZENORMAL];
    labContent.textColor = [UIColor darkGrayColor];
    _labContent = labContent;
    [self addSubview:labContent];
    labContent.numberOfLines = 0;
    labContent.preferredMaxLayoutWidth = screenWidth - 2*ViewMargine;
    
    EPMPhotoView* photoView = [EPMPhotoView new];
    _viewPhoto = photoView;
    [self addSubview:photoView];
    
    //约束
    [imgIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.offset(ViewMargine);
        make.width.height.mas_equalTo(35);
    }];
    [labName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgIcon);
        make.leading.equalTo(imgIcon.mas_trailing).offset(ViewMargine);
    }];
    [imgMemberShip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(labName);
        make.leading.equalTo(labName.mas_trailing).offset(ViewMargine);
    }];
    [labCreatTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(imgIcon);
        make.leading.equalTo(imgIcon.mas_trailing).offset(ViewMargine);
    }];
    
    [labSource mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(labCreatTime);
        make.leading.equalTo(labCreatTime.mas_trailing).offset(ViewMargine);
    }];
    [imgVerif mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imgIcon.mas_bottom);
        make.centerX.equalTo(imgIcon.mas_trailing);
    }];
    [imgVerif sizeToFit];
    
    [labContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top .equalTo(imgIcon.mas_bottom).offset(ViewMargine);
        make.leading.offset(ViewMargine);
        make.trailing.offset(-ViewMargine);
    }];
    [photoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.offset(ViewMargine);
        make.top.equalTo(labContent.mas_bottom).offset(ViewMargine);
    }];
     [self mas_makeConstraints:^(MASConstraintMaker *make) {
         make.bottom.equalTo(photoView).offset(ViewMargine);
     }];
    
}
- (void)setStatuesModel:(EPMStatuesViewModel *)statuesModel
{
    _statuesModel = statuesModel;
   
    [self.imgIcon sd_setImageWithURL:[NSURL URLWithString:statuesModel.homeModel.user.profile_image_url] placeholderImage:[UIImage imageNamed:@"avatar_default_small"]];
    self.labName.text = statuesModel.homeModel.user.name;
//    self.labContent.text = statuesModel.homeModel.text;
    self.imgVarif.image = statuesModel.vrifyImg;
    self.imgMemberShip.image = statuesModel.mBrankImg;
    self.labCreatTime.text = statuesModel.strDate;
    self.labSource.text = statuesModel.strSource;
    self.labContent.attributedText = statuesModel.originalAttr;
    
    [self.selfBottomConstraint deactivate];
    if (statuesModel.homeModel.pic_urls.count <= 0){
        self.viewPhoto.hidden = YES;
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
         _selfBottomConstraint = make.bottom.equalTo(_labContent).offset(ViewMargine);
        }];
    }else{
         self.viewPhoto.modelList = statuesModel.homeModel.pic_urls;
        self.viewPhoto.hidden = NO;
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
          _selfBottomConstraint = make.bottom.equalTo(self.viewPhoto).offset(ViewMargine);
        }];
    }
    
    
    
}

@end
